package demo;

import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.exception.ClientRequestException;
import com.huaweicloud.sdk.core.exception.ServerResponseException;
import com.huaweicloud.sdk.devsecurity.v1.DevSecurityClient;
import com.huaweicloud.sdk.devsecurity.v1.model.ShowSecAppTaskResultRequest;
import com.huaweicloud.sdk.devsecurity.v1.model.ShowSecAppTaskResultResponse;
import com.huaweicloud.sdk.devsecurity.v1.model.ShowSecAppTaskStatusRequest;
import com.huaweicloud.sdk.devsecurity.v1.model.ShowSecAppTaskStatusResponse;
import com.huaweicloud.sdk.devsecurity.v1.region.DevSecurityRegion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

public class ShowSecAppTaskResultDemo {
    private static final Logger logger = LoggerFactory.getLogger(ShowSecAppTaskResultDemo.class.getName());

    public static void main(String[] args) throws IOException {
        String ak = "<YOUR AK>";
        String sk = "<YOUR SK>";

        // 创建DevSecurityClient实例
        ICredential auth = new BasicCredentials().withAk(ak).withSk(sk);
        DevSecurityClient client = DevSecurityClient.newBuilder().withCredential(auth).withRegion(DevSecurityRegion.CN_NORTH_4).build();

        String taskId = "<YOUR TASK_ID>";
        // 创建<查询移动应用安全任务状态>请求，并指定任务ID
        ShowSecAppTaskStatusRequest showSecAppTaskStatusRequest = new ShowSecAppTaskStatusRequest().withTaskId(taskId);

        // 创建<获取移动应用安全任务结果>请求，并指定任务ID
        ShowSecAppTaskResultRequest showSecAppTaskResultRequest = new ShowSecAppTaskResultRequest().withTaskId(taskId);
        try {
            // 执行查询移动应用安全任务状态请求
            ShowSecAppTaskStatusResponse showSecAppTaskStatusResponse = client.showSecAppTaskStatus(showSecAppTaskStatusRequest);
            logger.info(showSecAppTaskStatusResponse.toString());

            // 执行获取移动应用安全任务结果请求
            ShowSecAppTaskResultResponse showSecAppTaskResultResponse = client.showSecAppTaskResult(showSecAppTaskResultRequest);
            logger.info(showSecAppTaskResultResponse.toString());
        } catch (ClientRequestException | ServerResponseException e) {
            logger.error(String.valueOf(e.getHttpStatusCode()));
            logger.error(e.toString());
        }
    }
}
